<?php


/**
 * Yutian OA Page Helpers
 *
 * @author kangell
 * @package Yutian OA
 * @subpackage Helpers
 */

/*
 * $Id: page_helper.php 81 2011-08-20 14:58:50Z leikou@163.com $
 */

/*
 * Page Helper
 *
 * Caculate record offset in terms of total_count, page and 
 * per page.
 *
 * @access public
 * @param int $page current page number
 * @param int $record_count total records counts
 * @param int $per_page record number that each page list
 *
 * @return array contain total_count, correct page num and
 *      per_page record number, format like below:
 *      array(
 *          'record_offset' => 0,
 *          'page' => 1,
 *          'total' => 50
 *      );
 */
if ( ! function_exists('oa_page'))
{
    function oa_page($page, $record_count, $per_page)
    {
        if ($record_count === 0)
        {
            return array(
                'record_offset' => 0,
                'page' => 0,
                'total' => 0,
            );
        }

        $total = ceil($record_count / $per_page);
        if ($page < 1)
        {
            $page = 1;
        }
        elseif ($page > $total)
        {
            $page = $total;
        }

        $record_offset = ($page - 1) * $per_page;

        return array(
            'record_offset' => $record_offset,
            'page' => $page,
            'total' => $total,
        );

        return $page_info;
    }
}


/* End of file: page_helper.php */
/* Location: ./application/helpers/page_helper.php */
